export default {
  props: {
    xLayoutOptions: {
      type: Object,
      default: null,
    },
    xLayoutIsShow: {
      type: Boolean,
      default: undefined,
    }
  },
  data() {
    return {
      xLayoutIsSubLevel: false,
      xLayoutIsOnShow: false,
      xLayuotSize: 'small',
      xLayoutTabsActive: '0',
      xLayoutListQuery: {},
      xLayoutListData: [],
      xLayoutListCurrentPage: 1,
      xLayoutListSize: 10,
      xLayoutListTotal: 0,
      xLayoutListQueryLeft: {},
      xLayoutListDataLeft: [],
      xLayoutListCurrentPageLeft: 1,
      xLayoutListSizeLeft: 1,
      xLayoutListTotalLeft: 10,
      xLayoutDetailType: 'detail',
      xLayoutDetailCanEdit: true,
      xLayoutDetailEditing: false,
      xLayoutDetailId: null,
      xLayoutDetailData: {},
      xLayoutIsEmbed: false,
      xLayoutListPages: 0
    }
  },
  watch: {
    xLayoutOptions: {
      handler(options, old) {
        if(options) {
          if(!uni.$x.auth.ready) return
          if(JSON.stringify(options)===JSON.stringify(old)) return

          this.mpageReady = uni.$x.auth.ready
          this.xLayoutDetailType = options._detail_type
          this.xLayoutDetailCanEdit = (this.xLayoutDetailType === 'add')?false:(options._detail_can_edit?(options._detail_can_edit!=='false'):true)
          this.xLayoutDetailId = options._detail_id
          this.xLayoutDetailEditing = this.xLayoutDetailType === 'add' || this.xLayoutDetailType === 'edit'
          this.xLayoutIsEmbed = true
          this.xLayoutOnLoad&&this.xLayoutOnLoad(options)
          
          if(this.xLayoutIsShow!==false) this.xLayoutOnShow&&this.xLayoutOnShow()
        } 
      },
      immediate: true
    },
    xLayoutIsShow: {
      handler(val, old){
        this.xLayoutIsOnShow = val
        if(this.xLayoutIsEmbed&&val&&!old) {
          this.xLayoutOnShow&&this.xLayoutOnShow()
        }
      },
      immediate: true,
    }
  },
  onLoad(options) {
    this.xLayoutIsSubLevel = options._sub_level
    this.xLayoutDetailType = options._detail_type
    this.xLayoutDetailCanEdit = (this.xLayoutDetailType === 'add')?false:(options._detail_can_edit?(options._detail_can_edit!=='false'):true)
    this.xLayoutDetailId = options._detail_id
    this.xLayoutDetailEditing = this.xLayoutDetailType === 'add' || this.xLayoutDetailType === 'edit'
  },
  onShow() {
    this.xLayoutIsOnShow = true
  },
  onHide() {
    this.xLayoutIsOnShow = false
  },
  methods: {
    xLayoutDetailEdit() {
      this.xLayoutDetailEditing = true
    },
    xLayoutDetailSave() {
      this.xLayoutDetailEditing = false
    },
    xLayoutDetailCancel() {
      this.xLayoutDetailEditing = false
    },
  }
}
  
